package Objetos
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	/**
	 * ...
	 * @author Pedro H. Machado Wigderowitz
	 */
	public class Heroi extends MovieClip
	{
		public static var BO_direita                :Boolean;
		public static var BO_esquerda               :Boolean;
		
		protected     var UI_velocidade             :uint;
		
		public function Heroi() 
		{
			UI_velocidade = 10;
			
			this.x = Main.getStage().stage.stageWidth / 2 + Main.getInstance(). MC_barradeenergia
			this.y = Main.getStage().stage.stageHeight - this.height
			
			Main.getStage().addEventListener(KeyboardEvent.KEY_DOWN, pressionar, false, 0, true);
			Main.getStage().addEventListener(KeyboardEvent.KEY_UP, soltar, false, 0, true);
		}
		
		public function pressionar(e:KeyboardEvent): void
		{
			switch (e.keyCode)
			{
				case Keyboard.RIGHT:
				BO_direita = true;
				break;
						
				case Keyboard.LEFT:
				BO_esquerda = true;
			}
	
		}
		
		public function soltar(e:KeyboardEvent):void
		{
			switch (e.keyCode)
			{
				case Keyboard.RIGHT:
				BO_direita = false;
				break;
						
				case Keyboard.LEFT:
				BO_esquerda = false;
			}
		}
		
		public function update():void
		{	
			if (BO_direita)
			{
				this.x += UI_velocidade;
			}
			
			if (BO_esquerda)
			{
				this.x -= UI_velocidade;
			}
			
			if (this.x >= Main.getStage().stage.stageWidth - this.width / 2)
			{
				this.x = Main.getStage().stage.stageWidth - this.width / 2
			}
			
			if (this.x <= Main.getInstance().MC_barradeenergia.x + Main.getInstance().MC_barradeenergia. width / 2 + this.width / 2)
			{
				this.x = Main.getInstance().MC_barradeenergia.x + Main.getInstance().MC_barradeenergia. width / 2 + this.width / 2
			}
		}
	}
}